package com.dao;

import java.sql.Connection;
import java.sql.SQLException;
import org.apache.commons.dbutils.handlers.BeanHandler;
import com.bean.User;
import com.tool.JdbcTool;

public class UserDao extends AncestorDao<User>
{

	
	private static UserDao instance = new UserDao("user");
	
	
	
	private UserDao(String tableName)
	{
		super(tableName);
	}
	
	
	
	public static UserDao getInstance()
	{
		return instance;
	}
	
	
	
	/**
	 * 根据账号和密码进行查询
	 */
	public User queryOne(String account, String password)
	{
		String sql = String.format("select * from %s where account=? and password=?", tableName);
		System.err.println("sql：" + sql);
		Connection conn = JdbcTool.getConnection();
		try
		{
			return qr.query(conn, sql, new BeanHandler<User>(User.class), account, password);
		}
		catch(SQLException e)
		{
			throw new RuntimeException(e);
		}
	}
	
	
	

}
